package com.brspace.qualitycontrol.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.brspace.qualitycontrol.entity.Leaveing;
import com.brspace.qualitycontrol.entity.vo.LeaveQueryVo;
import com.brspace.qualitycontrol.entity.vo.LeaveingVo;
import com.brspace.qualitycontrol.service.LeaveService;
import com.brspace.qualitycontrol.service.ProcessNodeService;
import com.brspace.qualitycontrol.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 请假 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-02
 */
@Api(description = "请假信息")
@CrossOrigin
@RestController
@RequestMapping("/admin/leave")
public class LeaveController {

    @Resource
    private LeaveService leaveService;
    @Resource
    private ProcessNodeService processNodeService;
    /**
     * 添加请假/请假申请
     * @Author: wangt
     * @Date: 2021-04-18 15:35:47
     */
    @ApiOperation("添加请假/请假申请")
    @PostMapping("addLeave")
    public R addLeave( Leaveing leaveing){
        return  leaveService.addLeave(leaveing);
    }

    /**
     * 添加测试
     * @Author: wangt
     * @Date: 2021-04-18 15:35:35
     */
    @ApiOperation("添加测试")
    @PostMapping("addTest")
    public R list(@RequestBody Leaveing leaveing){
        return  leaveService.addLeave(leaveing);
    }

    /**
     * 待审批分页列表
     * @Author: wangt
     * @Date: 2021-04-18 15:35:28
     */
    @ApiOperation("待审批分页列表")
    @PostMapping("list/{page}/{limit}")
    public R pageList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit){
        Page<Leaveing> pageParam = new Page<>(page, limit);
        IPage<Leaveing> pageModel = leaveService.selectPage(pageParam, null);
        List<Leaveing> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }
    /**
     * 待审批分页列表
     * @Author: wangt
     * @Date: 2021-04-18 15:35:28
     */
    @ApiOperation("待审批分页列表")
    @PostMapping("list1/{page}/{limit}/{id}")
    public R pageList1(
            @ApiParam(value = "当前页码",required = true) @PathVariable int page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
            @ApiParam(value="用户ID", required = true) @PathVariable String id){
        return leaveService.selectPage1(page,limit, null,id);
    }
    @ApiOperation("已审批分页列表")
    @PostMapping("stateList/{page}/{limit}/{id}")
    public R stateList1(@ApiParam(value = "当前页码",required = true) @PathVariable int page,
                        @ApiParam(value = "每页多少数据", required = true) @PathVariable int limit,
                        @ApiParam(value="用户ID", required = true) @PathVariable String id,
                        @ApiParam("查询条件")LeaveQueryVo leaveQueryVo){
        return leaveService.stateList1(page,limit, leaveQueryVo,id);
    }
    /**
     * 已审批分页列表
     * @Author: wangt
     * @Date: 2021-04-18 15:35:17
     */
    @ApiOperation("已批分页列表")
    @PostMapping("stateList/{page}/{limit}")
    public R stateList(
            @ApiParam(value = "当前页码",required = true) @PathVariable Long page,
            @ApiParam(value = "每页多少数据", required = true) @PathVariable Long limit,
            @ApiParam("查询条件")LeaveQueryVo leaveQueryVo){
        Page<Leaveing> pageParam = new Page<>(page, limit);
        IPage<Leaveing> pageModel = leaveService.stateList(pageParam, leaveQueryVo);
        List<Leaveing> records = pageModel.getRecords();
        long total = pageModel.getTotal();
        return R.ok().data("total",total).data("rows",records);
    }
    /**
     * 根据ID查询单个请假数据
     * @Author: wangt
     * @Date: 2021-04-18 15:34:49
     */
    @ApiOperation("根据ID查询")
    @PostMapping("findByLeave/{id}")
    public R findByLeave(@ApiParam(value = "id",required = true) @PathVariable String id){
        return R.ok().message("成功！").data("leave",leaveService.findById(id)).data("sort",processNodeService.findSort(id));
    }
    /**
     * 根据时间戳请假人数
     * @Author: wangt
     * @Date: 2021-04-18 15:34:34
     */
    @ApiOperation("获取请假人数")
    @PostMapping("leaNum")
    public R leaNum(LeaveingVo leaveingVo){
        int i = leaveService.leaNum(leaveingVo);
        return R.ok().message("成功").data("leaNum",i);
    }

    /**
     * 根据时间戳加班人数
     * @Author: wangt
     * @Date: 2021-04-18 15:34:24
     */
    @ApiOperation("获取加班人数")
    @PostMapping("pubNum")
    public R pubNum(LeaveingVo leaveingVo){
        int i = leaveService.pubNum(leaveingVo);
        return R.ok().message("成功").data("pubNum",i);
    }

    /**
     * 柱状图
     * @Author: wangt
     * @Date: 2021-04-18 15:35:06
     */
    @ApiOperation("获取请假假人数员图")
    @PostMapping("stateZhu")
    public R stateZhu(LeaveingVo leaveingVo){
        return leaveService.stateZhu( leaveingVo);
    }
    /**
     * 审核
     * @Author: wangt
     * @Date: 2021-04-18 15:34:07
     */
    @ApiOperation("审核")
    @PostMapping("examine/{userName}/{uid}")
    public R examine(
            @ApiParam(value = "下阶段办理人ID" ,required = true) @PathVariable String userName,
            @ApiParam(value = "当前节点办理人ID" , required = true) @PathVariable String uid,
            @ApiParam("对象类型") @RequestBody  Leaveing leaveing){
        return leaveService.examine(leaveing,userName,uid);
    }

    @ApiOperation("出勤率")
    @PostMapping("chuQin")
    public R chuQin(LeaveingVo leaveingVo){
        return leaveService.chuQin(leaveingVo);
    }

}

